package com.tubeonfire.entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

import javax.persistence.Id;

import org.jsoup.Jsoup;

import com.googlecode.objectify.annotation.Cached;
import com.googlecode.objectify.annotation.Indexed;
import com.googlecode.objectify.annotation.NotSaved;
import com.googlecode.objectify.annotation.Unindexed;

@Cached
public class Tube implements Serializable {
	public static final long serialVersionUID = 1L;
	@Id
	private String id = "";

	@Indexed
	private String playlistId = "";

	@Indexed
	private String channelId = "";

	@NotSaved
	private String channelName = "";

	@Unindexed
	private String title = "";

	@Unindexed
	private String alias = "";

	@Unindexed
	private String description = "";

	@Unindexed
	private String imageUrl = "";

	@Unindexed
	private long duration = 0;

	@Unindexed
	private String totalTime = "";

	@Unindexed
	private List<String> relatedTubes = new ArrayList<String>();

	@Unindexed
	private List<String> tags = new ArrayList<String>();

	@Unindexed
	private List<String> otherTags = new ArrayList<String>();

	@Indexed
	private String authorUrl = "";

	@Indexed
	private long youtubeView = 1;

	@Indexed
	private long view = 1;

	@Indexed
	private Date published = Calendar.getInstance().getTime();

	@Indexed
	private Date updated = Calendar.getInstance().getTime();

	@Indexed
	private long bumpPoint = 1;

	@Indexed
	private int status = 1;

	public Date getUpdated() {
		return updated;
	}

	public void setUpdated(Date updated) {
		this.updated = updated;
	}

	public String getSubDescription() {
		String result = Jsoup.parse(this.description).text();
		result = result.replace("\\s+$", "");
		result = result.replace("\"", " ");
		result = result.replace("\'", " ");
		if (result.length() > 188) {
			String subString = result.substring(0, 188);
			return (subString + "...");
		} else {
			return result;
		}
	}

	public String getSubTitle() {
		if (this.title.length() > 24) {
			String subString = this.title.substring(0, 24);
			return (subString + "...");
		} else {
			return this.title;
		}
	}

	public String getAuthor() {
		String[] spl = authorUrl.split("/");
		return spl[spl.length - 1];
	}

	public long getYoutubeView() {
		return youtubeView;
	}

	public void setYoutubeView(long youtubeView) {
		this.youtubeView = youtubeView;
	}

	public long getBumpPoint() {
		return bumpPoint;
	}

	public void setBumpPoint(long bumpPoint) {
		this.bumpPoint = bumpPoint;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getChannelName() {
		return channelName;
	}

	public void setChannelName(String channelName) {
		this.channelName = channelName;
	}

	public String getChannelId() {
		return channelId;
	}

	public void setChannelId(String channelId) {
		this.channelId = channelId;
	}

	public String getPlaylistId() {
		return playlistId;
	}

	public void setPlaylistId(String playlistId) {
		this.playlistId = playlistId;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getImageUrl() {
		return imageUrl;
	}

	public void setImageUrl(String imageUrl) {
		this.imageUrl = imageUrl;
	}

	public long getDuration() {
		return duration;
	}

	public void setDuration(long duration) {
		this.duration = duration;
	}

	public String getTotalTime() {
		return totalTime;
	}

	public void setTotalTime(String totalTime) {
		this.totalTime = totalTime;
	}

	public List<String> getRelatedTubes() {
		return relatedTubes;
	}

	public void setRelatedTubes(List<String> relatedTubes) {
		this.relatedTubes = relatedTubes;
	}

	public List<String> getTags() {
		return tags;
	}

	public void setTags(List<String> tags) {
		this.tags = tags;
	}

	public List<String> getOtherTags() {
		return otherTags;
	}

	public void setOtherTags(List<String> otherTags) {
		this.otherTags = otherTags;
	}

	public String getAuthorUrl() {
		return authorUrl;
	}

	public void setAuthorUrl(String authorUrl) {
		this.authorUrl = authorUrl;
	}

	public long getView() {
		return view;
	}

	public void setView(long view) {
		this.view = view;
	}

	public Date getPublished() {
		return published;
	}

	public void setPublished(Date published) {
		this.published = published;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

}
